package com.ruoyi.web.controller.vantController.customerController;

import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.service.vantservice.customerervice.ApiQRCodeService;
import com.ruoyi.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 刘锟
 * @Date: Created in 2021/3/9 10:05
 * @Description:
 * @Modified By:
 */
@RestController
@RequestMapping("/api/QRCode")
public class ApiQRCodeController {

    @Autowired
    private ApiQRCodeService apiQRCodeService;

    @Autowired
    private TokenUtils tokenUtils;

    //生成二维码
    @GetMapping("/create")
    public AjaxResult QRCode(HttpServletRequest request){
        CustomerLogin customerLogin = tokenUtils.getLoginCustomer(request);
        String qrCode = apiQRCodeService.createQRCode();
        if (qrCode.equals("500")) {
            return AjaxResult.error(500 , "二维码生成失败，请稍后重试");
        }
        Map<Object,Object> map = new HashMap<>();
        map.put("qrCode",qrCode);
        map.put("userId",customerLogin.getCustomerId());
        return AjaxResult.success(map);
    }
}
